<!--#include file="pjson.asp"-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>表管理</title>
<%
easp.include "h.asp"
%>
</head>
<body>
<%
input_h "sszid"
input_h "un"
%>
  <div class="layui-fluid">
    <div class="layui-card"><br>
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">表名</label>
            <div class="layui-input-block">
              <input type="text" name="tn" class="layui-input">
            </div>
          </div>
		  		<div class="layui-inline">
		<label class="layui-form-label">采集次数</label>
		<div class="layui-input-block">
		  <input type="text" name="cjcs" class="layui-input">
		</div>	
		</div>	
          <div class="layui-inline">			
		<%echo myopt2_no_required("prj_id","所属项目",sql2arr("select id,prn from prj"),iif(val("prj_id") = "",0,val("prj_id")))%>
			</div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="t_search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
 			  <button type="button" class="layui-btn" lay-submit lay-filter="t_add">新增表</button>			
			  <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="t_del_sel">删除所选</button>			
         </div>
        </div>
      </div>

      <div class="layui-card-body">
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="t_content">维护表</a>
			<a class="layui-btn layui-btn-xs" lay-event="t_show">查看表</a>
			<a class="layui-btn layui-btn-xs" lay-event="table_exp">导出</a>
			<a class="layui-btn layui-btn-xs" lay-event="t_edit">修改</a>
			<a class="layui-btn layui-btn-xs" lay-event="t_prj">选择所属项目</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="t_del">删除</a>			
		</script>
		<table id="t" lay-filter="t"></table><br>
      </div>
    </div>
  </div>

  <script src="/<%=rootpath%>/src/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '/<%=rootpath%>/src/layuiadmin/'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,admin = layui.admin	
    ,table = layui.table;
    form.render();
	table.render({
        elem: '#t',
        url: layui.setter.base + 'lib/reg.asp?action=t_list',
        cols: [[
		{type:'checkbox'},		
        {field: 'id',title: 'ID',width: 60,sort: true,hide:false},
        <%g_tbf "tn:150,prn:0,f1:0,cjcs:90","表名,所属项目,物理表名,采集次数"%>
        {fixed: 'right',width: 400,align: 'center',toolbar: '#barDemo'}]],
        id: 't',
        limit: 10,
        page: true,
        height: 475
    });
	<%
	Easp.Echo myjs1("add1.js","tn|t,title|新增受试者")
	' Easp.Echo myjs1("t_content.js","tn|t,title|维护表")
	%> 
    table.on('tool(t)',
    function(obj) {
        var data = obj.data;
		if (obj.event === 't_edit') {
			var _this = $(this);
			  layer.open({
				type: 2
				,title: '修改'
				,content: 't_frm.asp?now=' + new Date().getTime()+"&id="+data.id
				,maxmin: true
				,area: ['500px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post(layui.setter.base + 'lib/reg.asp?now=' + new Date().getTime(), {
							action: "t_edit",
							field
						},
						function(data) {
							if (data == '0') {
								layer.msg("成功!!");
							} else {
								layer.msg("失败！！ "+data);
							}
						});
					table.reload('t'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){
				}
				});				
			table.reload('t');
		}		
		else if (obj.event === 't_del') {
			var _this = $(this);
			layer.confirm('您确定删除此信息？' + data.id, {
				icon: 3,
				title: '提示信息'
			},
			function(index) {
				$.post(layui.setter.base + 'lib/reg.asp?now=' + new Date().getTime(), 
				{
					id: data.id
					,action: "t_del"
				},
				function(data) {
					if (data == '0') {
						layer.msg("成功!!");
					} else {
						layer.msg("失败！！ "+data);
					}
				});
				layer.close(index);
				table.reload('t');				
			});
		}	
		else if (obj.event === 't_prj') {
			var _this = $(this);
			  layer.open({
				type: 2
				,title: '选择表所属的项目'
				,content: 'list_t_prj.asp?now=' + new Date().getTime()+"&id="+data.id
				,maxmin: true
				,area: ['500px', '450px']
				});				
			table.reload('t');
		}		
		
		if (obj.event === 't_content') {
			var _this = $(this);
		var lindex=  layer.open({
				type: 2
				,title: '维护表__['+data.tn+']'
				,content: 't_content.asp?now=' + new Date().getTime()+"&id="+data.id+"&tn="+data.tn+"&dbName="+data.prn
				,maxmin: true
				,area: ['700px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post(layui.setter.base + 'lib/reg.asp?now=' + new Date().getTime(), {
							action: "t_edit",
							field
						},
						function(data) {
							if (data == '1') {
								layer.msg("成功!!");
							} else {
								layer.msg("失败！！ "+data);
							}
						});
					table.reload('t'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){				}
				});	
			layer.full(lindex);				
			table.reload('t');
		}
		else if (obj.event === 'table_exp') {
						var wlbm= data.f1;
						$.post(layui.setter.base + 'lib/reg.asp?now=' + new Date().getTime(), {
							action: "table_exp",
							wlbm:data.f1
						},
						function(data) {
							window.location.href=data;
						});			
		}
		else if (obj.event === 't_show') {
			var _this = $(this);
		var sszid=$("input[name='sszid']").val();
		var un=$("input[name='un']").val();
		layer.open({
				type: 2
				,title: '维护表'
				,content: 't_show.asp?now=' + new Date().getTime()+"&id="+data.id+"&tn="+data.tn+"&prn="+data.prn+"&ssbh="+sszid+"&name="+un+"&wlbm="+data.f1+"&prj_id="+data.prj_id
				,maxmin: true
				,area: ['500px', '750px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post(layui.setter.base + 'lib/reg.asp?now=' + new Date().getTime(), {
							action: "t_edit",
							field
						},
						function(data) {
							if (data == '1') {
								layer.msg("成功!!");
							} else {
								layer.msg("失败！！ "+data);
							}
						});
					table.reload('t'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){				}
				});				
			table.reload('t');
		}
	});		
  });
  </script>
</body>
</html>